﻿@model PaymentInfoModel
@using Logistics.Web.Models.Shipment

<script type="text/javascript">
    var pagename = "LogisticsPayment";
    var creditCard = {
        PaySuccessRe: function () {//获取已有信用卡的信息列表，如果有则显示，如果没有则不显示
            var that = this;
            $.ajax({
                cache: false,
                type: "POST",
                url: '@Url.Action("GetPaymentsCreditCard", "Order")',
                success: function (data) {
                    if (data != null && data.name === "GetPaymentList") {
                        $("#creditCardList").html(data.html);
                        that.ClickContinue();
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    showNotification('Failed to update the system.');
                }
            });
        },
        ClickContinue: function () {
            $("input[Value='Select']").click(function () {
                var creditCardId = $(this).attr("data-card");
                $("#CreditCard").val(creditCardId);
                $("#Continue").click();
            });
        },
        Init: function () {
            this.PaySuccessRe();
        }
    };
    $(document).ready(function () {
        if ($("#creditCardList").length) {
            creditCard.Init();
        }
        $("button").live("click", function (e) {
            e.stopPropagation();
        });
    });
    function loadCreditCardForm(url, data) {
        $('.payment-form-load').empty();
        $(".logistics-order-loading").show();
        $("#payment-info-form").hide();
        data['type'] = "logistics";
        $.ajax({
            cache: false,
            type: "POST",
            url: url,
            data: data,
            success: function (data) {
                $(".logistics-order-loading").hide();
                if (data.success) {
                    $('#form-additional').html(data);
                    $('.payment-form-load').html('<h3>Add Credit Card</h3><iframe class="payment-globalpayments-secureForm" src="' + data.url + '"></iframe>');
                    uid = data.uid;
                }
                else {
                    $("#payment-info-form").show();
                    showNotification(data.errors);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $(".logistics-order-loading").hide();
                showNotification('Failed to update the system.');
            }
        });
    }
    function removeCreditCard(url, data) {
        $.ajax({
            cache: false,
            type: "POST",
            url: url,
            data: data,
            success: function (data) {
                if (data.success) {
                    showNotification(data.errors);
                }
                else {
                    showNotification(data.errors);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                showNotification('Failed to update the system.');
            }
        });
    }
    function processCardOnFile(param) {
        submitPageRequest($('<input data-name="checkNewCard" data-value="@Boolean.TrueString">'), $("#payment-info-form"));
    }
    function showCreditCardConfirm() {
        $(".payment-action-button").append('<input type="button" class="btn btn-normal form-control" data-action="submit" value="Continue" />');
    }
    function showCVV() {
        $('#show-cvv').modal({

        });
    }
</script>

<div class="section-wrapper">
    
    @using (Html.BeginForm("PaymentInfo", "Shipment", FormMethod.Post, new { id = "paymentinfo-form" }))
    {
        @Html.HiddenFor(model => model.PackageId)
        @Html.HiddenFor(model => model.Date)
        @Html.HiddenFor(model => model.AddressId)
        @Html.Hidden("ReturnUrl", Model.ReturnUrl)
        @Html.Hidden("PaymentInfoTypeId", Model.PaymentInfoTypeId)
        <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
            <div class="window">
                <div class="window-title grad-lightgrey grad">
                    <div class="window-title-bar grad-titleshine grad">
                        <h2>Total</h2>
                    </div>
                </div>
                <div class="window-content space">
                    <table>
                        <tbody>
                            <tr class="summary-subtotal" style="border-top: 0;">
                                <td class="summary-item">Subtotal</td>
                                <td class="summary-price">$@Html.DisplayFor(model => model.Charge.SubTotalExclTax) @Html.HiddenFor(model => model.Charge.SubTotalExclTax)</td>
                            </tr>
                            <tr class="summary-fuelsurcharge">
                                <td class="summary-item">Surcharge @(Model.FuelSurchargeRate * 100)%</td>
                                <td class="summary-price">$@Html.DisplayFor(model => model.Charge.FuelSurchargeExclTax) @Html.HiddenFor(model => model.Charge.FuelSurchargeExclTax)</td>
                            </tr>
                            <tr class="summary-tax">
                                <td class="summary-item" style="padding-top: 0;">Tax @(Model.TaxRate * 100)%</td>
                                <td class="summary-price" style="padding-top: 0;">$@Html.DisplayFor(model => model.Charge.Tax) @Html.HiddenFor(model => model.Charge.Tax)</td>
                            </tr>
                            <tr class="summary-total">
                                <td class="summary-item">Total</td>
                                <td class="summary-price">$@Html.DisplayFor(model => model.Charge.Total) @Html.HiddenFor(model => model.Charge.Total)</td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="content-clear"></div>
                </div>
            </div>
        </div>

    <div id="creditCardList">
    </div>
    <div id="creditCardForm">
    </div>
    <div class="clear"></div>

        @*<div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
            @if (!String.IsNullOrEmpty(Model.CustomerAddress.FormattedAddress))
            {
                @Html.Partial("_ShipmentAddress", Model.CustomerAddress)
                @Html.Action("PaymentInfo", "Checkout")
            }
            else
            {
                <div class="address-book-new">
                    <div class='row edit-address edit-address-new'>
                        <div class="address-info">
                            @Html.ValidationSummary(false)
                            @Html.HiddenFor(model => Model.CustomerAddress.Id)
                            @Html.HiddenFor(model => Model.CustomerAddress.CountryId)
                            <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <div class="info-label">
                                    @Html.RequiredHint()
                                    @Html.LabelFor(model => Model.CustomerAddress.FirstName)
                                </div>
                                <div class="info-input">
                                    @Html.TextBoxFor(model => Model.CustomerAddress.FirstName, new { id = "FirstName-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                </div>
                            </div>
                            <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                <div class="info-label">
                                    @Html.RequiredHint()
                                    @Html.LabelFor(model => Model.CustomerAddress.LastName)
                                </div>
                                <div class="info-input">
                                    @Html.TextBoxFor(model => Model.CustomerAddress.LastName, new { id = "LastName-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                </div>
                            </div>
                            @if (Model.CustomerAddress.StreetAddressEnabled)
                            {
                                <div class="col col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                    <div class="info-label">
                                        @if (Model.CustomerAddress.StreetAddressRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.LabelFor(model => Model.CustomerAddress.Address1)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.Address1, new { id = "Address1-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                            @if (Model.CustomerAddress.CompanyEnabled)
                            {
                                <div class="col col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                    <div class="info-label">
                                        @if (Model.CustomerAddress.CompanyRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.LabelFor(model => Model.CustomerAddress.Company)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.Company, new { id = "Company-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                            @if (Model.CustomerAddress.StreetAddress2Enabled)
                            {
                                <div class="col col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                    <div class="info-label">
                                        @Html.LabelFor(model => Model.CustomerAddress.Address2)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.Address2, new { id = "Address2-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                            <div class="col col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                <div class="info-label">
                                    @Html.RequiredHint()
                                    @Html.LabelFor(model => Model.CustomerAddress.Email)
                                </div>
                                <div class="info-input">
                                    @Html.TextBoxFor(model => Model.CustomerAddress.Email, new { id = "Email-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                </div>
                            </div>
                            @if (Model.CustomerAddress.ZipPostalCodeEnabled)
                            {
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @if (Model.CustomerAddress.ZipPostalCodeRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.LabelFor(model => Model.CustomerAddress.ZipPostalCode)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.ZipPostalCode, new { id = "ZipPostalCode-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                            @if (Model.CustomerAddress.CityEnabled)
                            {
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @if (Model.CustomerAddress.CityRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.LabelFor(model => Model.CustomerAddress.City)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.City, new { id = "City-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>

                            }
                            @if (Model.CustomerAddress.PhoneEnabled)
                            {
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @if (Model.CustomerAddress.CellPhoneRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.LabelFor(model => Model.CustomerAddress.CellPhoneNumber)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.CellPhoneNumber, new { id = "CellPhoneNumber-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @Html.LabelFor(model => Model.CustomerAddress.PhoneNumber)
                                    </div>
                                    <div class="info-input">
                                        @Html.TextBoxFor(model => Model.CustomerAddress.PhoneNumber, new { id = "PhoneNumber-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                            @if (Model.CustomerAddress.CountryEnabled)
                            {
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @Html.LabelFor(model => Model.CustomerAddress.CountryName)
                                    </div>
                                    <div class="info-input">
                                        @Html.DisplayFor(model => Model.CustomerAddress.CountryName)
                                        @Html.HiddenFor(model => Model.CustomerAddress.CountryId)
                                    </div>
                                </div>
                            }
                            @if (Model.CustomerAddress.CountryEnabled && Model.CustomerAddress.StateProvinceEnabled)
                            {
                                <div class="col col-xs-3 col-sm-3 col-md-3 col-lg-3">
                                    <div class="info-label">
                                        @Html.LabelFor(model => Model.CustomerAddress.StateProvinceId)
                                    </div>
                                    <div class="info-input">
                                        @Html.DropDownListFor(model => Model.CustomerAddress.StateProvinceId, Model.CustomerAddress.AvailableStates, new { id = "StateProvinceId-" + Model.CustomerAddress.Id.ToString(), Class = "form-control" })
                                    </div>
                                </div>
                            }
                        </div>
                        <div class="window-content space">
                            <div class="buttons">
                                <input type="button" data-action="submit" class="btn btn-primary" id="save-receiver-delivery-address" value="@T("Common.Save")" />
                            </div>
                        </div>
                        <div class="content-clear"></div>
                    </div>
                </div>
            }
        </div>*@
    }
</div>